import { strict as assert } from 'node:assert';

import { describe, it } from 'vitest';

import { EggCore } from '../src/egg.ts';
import { Lifecycle } from '../src/lifecycle.ts';

describe('test/lifecycle.test.ts', () => {
  it('should forbid adding hook after initialization', () => {
    const lifecycle = new Lifecycle({
      baseDir: '.',
      app: new EggCore(),
    });

    lifecycle.init();
    assert.throws(() => {
      lifecycle.addBootHook(
        class Hook {
          app: EggCore;
          constructor(app: EggCore) {
            this.app = app;
          }
          configDidLoad() {
            console.log('test');
          }
        },
      );
    }, /do not add hook when lifecycle has been initialized/);

    assert.throws(() => {
      lifecycle.addFunctionAsBootHook(() => {
        console.log('test');
      });
    }, /do not add hook when lifecycle has been initialized/);
  });
});
